package com.wpr.shop.modules.global.validate;

/**
 * describe:
 *
 * @author zhanglisheng
 * @date 2018/10/25
 */
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    protected ErrorCode errorCode;

    public BaseException(ErrorCode errorCode) {
        this.errorCode = errorCode;
    }

    public BaseException(String msg, ErrorCode errorCode) {
        super(msg);
        this.errorCode = errorCode;
    }

    public BaseException(Exception e, ErrorCode errorCode) {
        super(e);
        this.errorCode = errorCode;
    }

    public BaseException(String msg, Exception e, ErrorCode errorCode) {
        super(msg, e);
        this.errorCode = errorCode;
    }

    public String getMessage() {
        StringBuilder builder = new StringBuilder();
        String msg = builder.append(super.getMessage() == null ? "" : super.getMessage()).append(this.errorCode.getComment()).toString();
        return msg;
    }

    public ErrorCode getErrorCode() {
        return this.errorCode;
    }

    public int getErrorCodeValue() {
        return this.errorCode.getValue();
    }

    protected void setErrorCode(ErrorCode errorCode) {
        this.errorCode = errorCode;
    }
}
